<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>js计时器</title>
</head>
<body>
<input type="text" value="00:00" id="in1">
<input type="button" value="开始" id="in2">
<input type="button" value="暂停" id="in3">
<input type="button" value="重置" id="in4">
<input type="button" value="计次" id="in5">
<script>
    var Txt=document.getElementById("in1");
    var Start=document.getElementById("in2");
    var Stop=document.getElementById("in3");
    var Reset=document.getElementById("in4");
    var once=document.getElementById("in5");
    var n= 0, timer;
    //开始计时
    Start.onclick= function () {
        clearInterval(timer);
        timer=setInterval(function () {
            n++;
            var m=parseInt(n/60);
            var s=parseInt(n%60);
            Txt.value=toDub(m)+":"+toDub(s);
            return mm=Txt.value;
        },1000/60);
    };
    //暂停并且清空计时器
    Stop.onclick= function () {
        clearInterval(timer);
    }
    //重置
    Reset.onclick= function () {
        Txt.value="00:00";
        n=0;
    }
    //补零
    function toDub(n){
        return n<10?"0"+n:""+n;
    }
    once.onclick = function(){
        var i = 0;
        var np = document.createElement('input');
        var str = mm+i++;
        np.value = (str.substr(0,5));
        document.body.appendChild(np);
    }
</script>
</body>
</html>